package zhuoer.adv1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class GetNextBirthday {

	public static void main(String[] args) {
		// 获得下一个生日
		Scanner input = new Scanner(System.in);
		SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
		sim.setLenient(false);
		Calendar ss = Calendar.getInstance();

		int year = ss.get(Calendar.YEAR);

		System.out.println("请输入你的生日:");
		String a = input.next();
		for (int i = 1; i <= 9; i++) {
			try {
				String str = year + "-" + a;
				Date date = sim.parse(str);
				// ss.setTime(date);
				if (System.currentTimeMillis() < date.getTime()) {
					// 今年的生日没到
					int days = (int) ((date.getTime() - System
							.currentTimeMillis()) / 1000 / 86400) + 1;
					System.out.println("距您下次生日还有" + days + "天");
					return;
				}
				year++;

			} catch (ParseException e) {
				// e.printStackTrace();
				year++;
			}
		}
		System.out.println("输入不是合法的月份！");

	}

}
